package src.com.atguigu02.iterator;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Collection;

/**
 * ClassName: PersonTest
 * Description:
 *
 * @Author liu
 * @Create 2024/11/24 15:45
 * @Version 1.0
 */
public class ForTest {
    //接口Collerction,是Object类的
    @Test
    public void test1(){
        Collection coll = new ArrayList();

        coll.add("AA");
        coll.add("BB");
        Person p1 = new Person("Tom",12);
        coll.add(p1);
        coll.add(128);//自动装箱
        coll.add(new String("谷"));

        //for(要遍历的集合或数组元素的类型 临时变量 : 要遍历的集合或数组变量)
          for(Object obj: coll){
              System.out.println(obj);
          }
    }

    //int类型
    @Test
    public void test2(){
      int[] arr = new int[]{1,2,3,4,5};
      for (int i: arr){
          System.out.println(i);
      }
    }

    //String类
    @Test
    public void test3(){
      String[] arr = new String[]{"LL","ff","EEe"};
      for (String s:arr){
          System.out.println(s);
      }
    }

}
